package com.dhcc.sds.base.controller;


import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import com.dhcc.sds.base.entity.SdsQcentityItemEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;



import com.dhcc.sds.base.entity.SdsQceitemDicEntity;
import com.dhcc.sds.base.service.ISdsQceitemDicService;


/**
 * 质控项目值域字典表
 * 
 * @ClassName: SdsQceitemDicController
 * @Description: TODO
 * @author sunyingjie
 * @date 2021-03-22 10:10:51
 */
@Controller
@RequestMapping("${sys.backendPath}/sds/sdsqceitemdic")
public class SdsQceitemDicController extends BaseController {

	private String PREFIX = "/backend/sds/sdsqceitemdic/";

	@Autowired
	private ISdsQceitemDicService sdsQceitemDicService;
	

    /**
     * 跳转到质控项目值域字典表列表首页
     */
    @RequestMapping("/{entityItemId}")
    public String index(@PathVariable Long entityItemId, Model model) {
        model.addAttribute("entityItemId",entityItemId);
        return PREFIX + "sdsqceitemdic.html";
    }
	
    /**
     * 跳转到新增质控项目值域字典表
     */
    @RequestMapping("/to_add/{entityItemId}")
    public String toAdd(@PathVariable Long entityItemId, Model model) {
        model.addAttribute("entityItemId", entityItemId);
        return PREFIX + "sdsqceitemdic_add.html";
    }
	
	/**
     * 跳转到修改质控项目值域字典表
     */
    @RequestMapping("/to_update/{sdsQceitemDicId}")
    public String toUpdate(@PathVariable Long sdsQceitemDicId, Model model) {
        SdsQceitemDicEntity sdsQceitemDic = this.sdsQceitemDicService.selectById(sdsQceitemDicId);
        model.addAttribute("sdsQceitemDic",sdsQceitemDic);
        return PREFIX + "sdsqceitemdic_edit.html";
    }

    /**
     * 获取质控项目值域字典表列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list/{entityItemId}")
    @ResponseBody
    public Object list(@PathVariable Long entityItemId, @RequestParam Map<String, Object> params) {
		Page<SdsQceitemDicEntity> page = new PageFactory<SdsQceitemDicEntity>().dataGridPage();
		params.put("entityItemId",entityItemId);
        List<SdsQceitemDicEntity> result = this.sdsQceitemDicService.page(page,params);
        page.setRecords((List<SdsQceitemDicEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增质控项目值域字典表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdsQceitemDicEntity sdsQceitemDic) {
        if (CommonUtil.isOneEmpty(sdsQceitemDic)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdsQceitemDic.setUpdateFlag(1);
        sdsQceitemDic.insert();
        return R.ok();
    }

    /**
     * 删除质控项目值域字典表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdsQceitemDicId) {
        SdsQceitemDicEntity entity = new SdsQceitemDicEntity();
        entity.setId(sdsQceitemDicId);
        entity.setIsActive(0);
        entity.setUpdateFlag(1);
        this.sdsQceitemDicService.updateById(entity);
        return R.ok();
    }

    /**
     * 修改质控项目值域字典表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdsQceitemDicEntity sdsQceitemDic) {
        if (CommonUtil.isOneEmpty(sdsQceitemDic)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdsQceitemDicEntity old = this.sdsQceitemDicService.selectById(sdsQceitemDic.getId());

        old.setEntityItemId(sdsQceitemDic.getEntityItemId());
        old.setBtCode(sdsQceitemDic.getBtCode());
        old.setBtDesc(sdsQceitemDic.getBtDesc());
        old.setIsActive(sdsQceitemDic.getIsActive());
        old.setUpdateFlag(1);
        old.updateAllColumnById();
        return R.ok();
    }
	
}
